import { request, http } from '.'

/*
商城
*/

// 商城分类
export const getShopCategory = async () => {
	return http(`/api/v1/product/category/list`, 'GET', {})
}


// 店铺——>商品详情
export const getStoreProductInfo = async (id: number) => {
	return request(`/api/v1/product/${id}`, 'GET', {})
}

// export const paymentHadle = async (data: { // 支付
// 	orderId: number,
// 	payType: number
// }) => { // /api/v1/orders/{orderId}/pay/{payType}  /api/v1/orders/pay
// 	return request(`/api/v1/orders/${data.orderId}/pay/${data.payType}`, 'PUT', {})
// }

export const paymentHadle = async (// 支付
	payCode: string,
	payType: number,
	payPassword: string,
) => { // 
	return request(`/api/v1/pay/${payCode}`, 'PUT', {payType, payPassword})
}

export const canclePaymentHadle = async (// 取消支付
	payCode: string, 
) => { // 
	return request(`/api/v1/pay/${payCode}/cancel`, 'PUT', {})
}

// export const createOrder = async (data: { // 创建订单
// 	productId: number,
// 	productQuantity: number,
// 	appointmentTime: string,
// 	remark: string
// 	payType: number
// }) => { 
// 	return request(`/api/v1/orders`, 'POST', data)
// }

export const createOrder = async (data: { // 创建订单
	products: Array<{
		sku: string,
		quantity: number
	}>,
	remark: string,
	payType: number,
	addressesId?: number
	}) => request(`/api/v1/orders`, 'POST', data);
	

export const ordersStatus = async (id: number) => { 
	return request(`/api/v1/orders/${id}`, 'GET', {})
}


export const searchGoods = async (// 搜索
	data: {
		page: number,
		pageSize: number,
		storeId?: number,
		businessType: number,
		categoryId?: number, 
		productName?: string,
	}
) => { // 
	return http(`/api/v1/product/list`, 'GET', data)
}

